<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets">

<h:head>
	<link rel="stylesheet" type="text/css" href="resources/css/estilo.css" />
</h:head>
<h:body>
	<h:outputText value="Gerenciador de produtos" />
	<h:form>
		<h:commandButton action="#{gestaoBean.destaque}" value="Pintar"
			binding="#{gestaoBean.button}" />
		<h:commandLink value="Sobre este sistema" action="about?faces-redirect=true">
			<f:actionListener binding="#{reg}"/>
		</h:commandLink>

		<h:panelGrid columns="2">
			<h:outputText value="Nome:" />
			<h:inputText value="#{gestaoBean.produto.nome}" />

			<h:outputText value="Fabricante:" />
			<h:inputText value="#{gestaoBean.produto.fabricante}" />

			<h:outputText value="Categoria:" />
			<h:inputText value="#{gestaoBean.produto.categoria}" />
			
			<h:commandButton action="#{gestaoBean.adicionar}" value="Adicionar" 
			actionListener="#{gestaoBean.verificaInclusao}">
				<f:actionListener binding="#{reg}"/>
			</h:commandButton>
			
		</h:panelGrid>
	</h:form>
	
	<h:outputText value="Mensagem:" style="display:none;" binding="#{gestaoBean.mensagem}" />
	<h:form>
	<table class="tb-produtos">
	<tr>
		<th>ID</th>
		<th>Nome</th>
		<th>Fabricante</th>
		<th>Categoria</th>		
	</tr>
	
	<ui:repeat var="item" value="#{gestaoBean.produtos}" varStatus="count">
		<tr>
			<td><h:outputText value="#{count.index + 1}" /></td>
			<td>#{item.nome}</td>			
			<td>#{item.fabricante}</td>
			<td>#{item.categoria}</td>
			<td><h:commandButton value="Excluir" action="#{gestaoBean.excluir}">
				<f:setPropertyActionListener target="#{gestaoBean.produtoSelecionado}" value="#{item}" />
			</h:commandButton>
			</td>
		</tr>
	</ui:repeat>
	</table>
	</h:form>
	

</h:body>
</html>
